package org.jeecg.modules.wlhy.hycfg.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.common.constant.CacheConstant;
import org.jeecg.modules.wlhy.hycfg.entity.HyCfg;
import org.jeecg.modules.wlhy.hycfg.mapper.HyCfgMapper;
import org.jeecg.modules.wlhy.hycfg.service.IHyCfgService;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * @Description: hy_cfg
 * @Author: jeecg-boot
 * @Date:   2022-09-28
 * @Version: V1.0
 */
@Service
public class HyCfgServiceImpl extends ServiceImpl<HyCfgMapper, HyCfg> implements IHyCfgService {

    @Override
    public boolean checkCodeExist(String cfgCode) {
        return this.count(new QueryWrapper<HyCfg>().eq("cfg_code",cfgCode))  > 0;
    }

    @Override
    public boolean checkCodeExistOutId(String cfgCode, String id) {
        return this.count(new QueryWrapper<HyCfg>().eq("cfg_code",cfgCode).ne("id",id))  > 0;
    }

    @Override
    @Cacheable(unless="#result == null", cacheNames= CacheConstant.CACHE_HY_CFG, key="#cfgCode")
    public HyCfg getByCode(String cfgCode) {
        return this.getOne(new QueryWrapper<HyCfg>().eq("cfg_code", cfgCode));
    }

    @Override
    @CacheEvict(cacheNames= CacheConstant.CACHE_HY_CFG, key="#entity.cfgCode")
    public boolean updateById(HyCfg entity) {
        return baseMapper.updateById(entity)==1;
    }
}
